<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
    <meta name="author" content="Coderthemes">

    <link rel="stylesheet" href="/adminstatic/base/base.css"/>
    <script src="/adminstatic/base/baseCss.js"></script>

    <style type="text/css">
        html, body {
            background: #fff;
        }

        .layui-input-block {
            margin-left: 0;
        }
    </style>
</head>

<body class="fixed-left">

<!-- Begin page -->
<div id="wrapper" style="overflow: auto;">

    <div class="container">
        <div class="panel panel-default" style="box-shadow: none">
            <div class="panel-body">
                <form class="layui-form" action="">
                    <input type="hidden" name="id" value="<%=id%>"/>
                    <input type="hidden" name="hotspot_flag" value="<%=hotspot_flag%>"/>
                    <input type="hidden" name="content" value="<%=content%>"/>
                    <div id="inputForm" class="form-horizontal">
                        <div class="row" style="padding:0 20px">
                            <div class="form-group">
                                <div class="col-md-12">
                                    <label for="title"><small class="notNullFlag">*</small> 公告标题</label>
                                    <input class="form-control" type="text" id="title" name="title"
                                           value="<%=title%>" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-12">
                                    <label><small class="notNullFlag">*</small> 设为热点</label>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block" id="hotspot">
                                            <input type="radio" name="hotspot" id="yes" value="1" title="是" lay-filter="hotspot">
                                            <input type="radio" name="hotspot" id="no" value="0" title="否" lay-filter="hotspot" checked>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-md-12">
                                    <label for="editor"><small class="notNullFlag">*</small> 内容</label>
                                    <div id="text-item"></div>
                                    <textarea id="editor" name="editor" style="width:100%;height:500px;"></textarea>
                                </div>
                            </div>


                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div id="actions">
            <button type="button" class="layui-btn layui-btn-normal" id="submitBtn">保存</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="closeIframe()">取消</button>
        </div>
    </div><!-- panel-body -->
</div> <!-- panel -->

</div> <!-- container -->

</div>
<!-- END wrapper -->

<script src="/adminstatic/base/base.js"></script>
<script type="text/javascript">
    var hotspotId = $("input[name='hotspot_flag']").val();
    var contentHtml = $("input[name='content']").val();
    console.log(contentHtml)
    if (parseInt(hotspotId) === 1) {
        $("#yes").attr("checked", "true");
    } else {
        $("#no").attr("checked", "true");
    }

    var hotspot = '';
    var html = '';
    layui.use('form', function () {
        var form = layui.form;
        hotspot = $("input[name='hotspot']:checked").val();
        form.on('radio(hotspot)', function (data) {
            //获取单选的值
            hotspot = data.value
            console.log(hotspot)
        });
    });

    ckeditor();
    $("#editor").val(contentHtml);

    $("#submitBtn").click(function () {
        console.log(hotspot)
        var id = $("input[name='id']").val();
        var title = $("input[name='title']").val();
        var content =  CKEDITOR.instances.editor.getData();
        if (!vaildeParam(title)) {
            layer.msg("请输入标题", {icon: 5});
            return;
        }
        if (!vaildeParam(content)) {
            layer.msg("请输入公告内容", {icon: 5});
            return;
        }


        var api = '/admin/announcement/update';
        var data = {
            "id": id,
            "title": title,
            "hotspot": hotspot,
            "content": content
        }

        postJSON(api, data, function (res) {
            cleanSuccess(res)
        })

    })

</script>


</body>
</html>